//
//  TwoVC.m
//  timelyRain
//
//  Created by Jiafei Wei on 16/8/5.
//  Copyright © 2016年 Jiafei Wei. All rights reserved.
//

#import "TwoVC.h"
#import "WphoneSettingCell.h"
#import "HttpTool.h"
#import "BindTool.h"
#import "RunSucessInfo.h"
#import "SweepCodeBinding.h"
@interface TwoVC ()<UITableViewDelegate,UITableViewDataSource>
{
    NSMutableArray *dataArr;
}
@property (weak, nonatomic) IBOutlet UITableView *table;
@end

@implementation TwoVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [super setTitleView:self.view withName:@"wphone 设置"];
    _table.delegate =self;
    _table.dataSource =self;
    dataArr =[NSMutableArray array];
    [self settingData];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    NSArray *arr =[dataArr objectAtIndex:section];
    return arr.count;
}
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.section==0){
        if (indexPath.row==0) {
            
        }else if(indexPath.row==1){
            //进行解绑的操作
            [self unbindWatchToserver:[BindTool share].deviceInfo.watch_sn with:[BindTool share].deviceInfo.device_sn];
        }else{
        }
    }
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSArray *arry =[dataArr objectAtIndex:indexPath.section];
    Settinginfo *info =[arry objectAtIndex:indexPath.row];
    WphoneSettingCell *cell =[WphoneSettingCell setWphoneSettingCellWithTableView:tableView];
    cell.name.image =[UIImage imageNamed:info.nameImage];
    cell.nameText.text=info.name;
    cell.nameDes.text=info.dec;
    return cell;
}

-(void)settingData{
    Settinginfo *info1 =[[Settinginfo alloc]init];
    info1.nameImage=@"热点";
    info1.name=@"热点";
    info1.dec=@"";
    Settinginfo *info2 =[[Settinginfo alloc]init];
    info2.nameImage=@"绑定与解绑";
    info2.name=@"绑定与解绑";
    info2.dec=@"与绑定";
    Settinginfo *info3 =[[Settinginfo alloc]init];
    info3.nameImage=@"关于wphone";
    info3.name=@"关于 wphone";
    info3.dec=@"";
    [dataArr addObject:@[info1,info2,info3]];
    
    Settinginfo *info4 =[[Settinginfo alloc]init];
    info4.nameImage=@"软件版本0";
    info4.name=@"软件版本";
    info4.dec=@"";
    Settinginfo *info5 =[[Settinginfo alloc]init];
    info5.nameImage=@"关于及时雨";
    info5.name=@"关于及时雨";
    info5.dec=@"";
    Settinginfo *info6 =[[Settinginfo alloc]init];
    info6.nameImage=@"第三方推送";
    info6.name=@"第三方推送";
    info6.dec=@"";
    [dataArr addObject:@[info4,info5,info6]];
}

-(void)unbindWatchToserver:(NSString *)watch_sn with:(NSString *)device_sn{
    NSLog(@"watch_sn====%@,device_sn ====%@",watch_sn,device_sn);
     __weak typeof(self) weakSelf = self;
    NSString *url =[apiUrl stringByAppendingString:unbindWatch];
    NSDictionary *paramerter =@{@"watch_sn":watch_sn,@"device_sn":device_sn};
    [HttpTool Post:url parameters:paramerter success:^(id responseObject) {
        NSString *str = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
        NSLog(@"unbindWatchToserver----=== %@",str);
        RunSucessInfo *success =[RunSucessInfo mj_objectWithKeyValues:responseObject];
        if (success.status) {
            SweepCodeBinding *codeBind =[[SweepCodeBinding alloc]init];
            [weakSelf.navigationController pushViewController:codeBind animated:YES];
        }else{
            
        }
        //解绑完之后就进行跳转
    } failure:^(NSError *error) {
        
    }];
}
@end

@implementation Settinginfo

@end
